<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class Plugin_ModuleLayoutLoader extends Zend_Controller_Plugin_Abstract
{

    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {

        $module = $request->getModuleName();
        $layout = Zend_Layout::getMvcInstance();
        // check module and automatically set layout
        $layoutsDir = $layout->getLayoutPath();
		$auth = Zend_Auth::getInstance();

		if(!$request->isXmlHttpRequest()) //if not ajax request
		{
          
			// check if module layout exists else use default
			if( $module != 'default' && $module!='build' &&  file_exists($layoutsDir . DIRECTORY_SEPARATOR . "user.phtml")) {
				$layout->setLayout('user');
			} 
                        elseif($module == 'build')
                        {
                            $layout->setLayout('layout');
                            
                        }    
                        else {
				$layout->setLayout("layout");
			}
		}
		else
		{
			$layout->setLayout("ajaxblank");
        	}
	}
}

?>
